package com.daocao.jy.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.daocao.jy.R;
import com.daocao.jy.api.model.OilcardListModel;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class OilChangeAdapter extends ItemAdapter<OilcardListModel.DatasBean, OilChangeAdapter.DefaultHolder> {


    public OilChangeAdapter(Context context) {
        super(context);
    }

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_oil_change, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {
        OilcardListModel.DatasBean item = getItem(position);
        if (item.ctype.equals("1")) {
            holder.txtOilType.setText("中国石化");
            holder.imgIcon.setImageResource(R.mipmap.img_type_shihua);
        } else if (item.ctype.equals("2")) {
            holder.txtOilType.setText("中国石油");
            holder.imgIcon.setImageResource(R.mipmap.img_type_shiyou);
        }
        holder.txtOilCard.setText(item.card_number);
        holder.layoutTotal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onChooseListener != null) {
                    onChooseListener.onClick(item.id, item.ctype, item.card_number);
                }
            }
        });
    }

    class DefaultHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.img_icon)
        ImageView imgIcon;
        @BindView(R.id.txt_oil_type)
        TextView txtOilType;
        @BindView(R.id.txt_oil_card)
        TextView txtOilCard;
        @BindView(R.id.layout_total)
        RelativeLayout layoutTotal;

        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    private OnChooseListener onChooseListener;

    public void setOnChooseListener(OnChooseListener onChooseListener) {
        this.onChooseListener = onChooseListener;
    }

    public interface OnChooseListener {
        void onClick(String id, String ctype, String card_number);
    }
}
